home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-29 | 3.3 KB | 173 lines | [TEXT/CWIE] |
- #include <profiler.h>
- #include "dsm.h"
-
- #ifndef __POWERPC__
- int errno = 0;
- #endif
-
- static Boolean CheckForCmdPeriod (void)
- {
- KeyMap keys;
-
- GetKeys (keys);
- if(keys [1] & 0x00800000) // command
- {
- if(keys[1] & 0x00008000) // period
- {
- FlushEvents (mDownMask + mUpMask, 0);
- return TRUE;
- }
- }
- return FALSE;
- }
-
- static void InitToolBox()
- {
- EventRecord event;
- short count;
-
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- SetEventMask(everyEvent);
-
- for (count = 1; count <= 3; count++) {
- MoreMasters();
- EventAvail(everyEvent, &event);
- }
- FlushEvents(everyEvent, 0);
- }
-
- void main(void)
- {
- OSErr iErr;
- word i=1, track, polyphony=2;
- EventRecord theEvent;
-
- InitToolBox();
-
- // Create new synthesiser:
-
- // Mixing Freq: 44 kHz
-
- // Stereo: True Lerping: True
- // 16-Bit: True Looping: False
- // Surround: True
-
- #ifdef __POWERPC__
- Synthesiser *dsm = new Synthesiser(PM_SURROUND + PM_STEREO + PM_INTERP + PM_16BIT, mix44kHz, true);
- #else
- Synthesiser *dsm = new Synthesiser(PM_SURROUND + PM_STEREO + PM_INTERP, mix22kHz, true);
- #endif
-
- SFReply reply;
- SFTypeList typeList = { '????' };
- Point where = { -1, -1 };
-
- SFGetFile(where, "\p", NULL, -1, typeList, NULL, &reply);
- if (!reply.good) {
- ExitToShell();
- }
-
- FileMod *song = new FileMod(reply);
-
- // To load a mod from resource, uncomment next line:
- // ResMod *song = new ResMod('song', 128);
-
-
- // Always check if mod has loaded, or you might crash.
-
- if (song->getError())
- {
- delete dsm;
- delete song;
-
- return;
- }
-
- // You're only allowed to attach one song to synthesiser at a time.
- // AttachMod() must not be called while synthesiser is active
-
- dsm->AttachMod(*song);
-
- // Let the music play!
-
- dsm->PlayStart();
-
- while (!CheckForCmdPeriod() && !dsm->IsDone())
- {
- if (WaitNextEvent(everyEvent, &theEvent, 0, NULL))
- switch (theEvent.what) {
- case keyDown:
- case autoKey:
- {
- switch (theEvent.message & charCodeMask)
- {
- case '\r':
- polyphony = (polyphony+1) % 3;
- switch (polyphony)
- {
- case 0:
- dsm->SetMixMode(dsm->GetMixMode()
- & ~PM_STEREO & ~PM_SURROUND);
- break;
- case 1:
- dsm->SetMixMode(dsm->GetMixMode()
- | PM_STEREO & ~PM_SURROUND);
- break;
- case 2:
- dsm->SetMixMode(dsm->GetMixMode()
- | PM_STEREO | PM_SURROUND);
- break;
- }
- break;
- case '-':
- {
- uword mastervol = dsm->GetGlobalVol();
-
- dsm->SetGlobalVol((mastervol>=5) ? mastervol-5 : 0);
- break;
- }
- case '+':
- {
- uword mastervol = dsm->GetGlobalVol();
-
- dsm->SetGlobalVol((mastervol<=250) ? mastervol+5 : 255);
- break;
- }
- case '[':
- dsm->GoToPrevPattern();
- break;
- case ']':
- dsm->GoToNextPattern();
- break;
- case ' ':
- dsm->TogglePause();
- break;
- default:
- short key = (theEvent.message & charCodeMask) - 'A';
-
- if ((key >= 0) && (key < dsm->GetMixChannels()-1))
- {
- dsm->SetFreq(0, 16316);
- dsm->SetBalance(0, 128);
- dsm->SetVolume(0, 64);
- dsm->VoicePlay(0, 0, key);
- }
- }
- }
- }
- }
-
- dsm->PlayStop(true);
-
- delete song;
- delete dsm;
-
- FlushEvents(everyEvent, 0);
- }
-